﻿using System;
using System.Collections;
using System.Data;
using Lib.Data;
using Lib.Utils;

namespace MS.INV.Systems
{
    public class ZZ_System : Lib.Bases.BaseClass
    {
        #region Prop
        public System.Int32 ID
        {
            get;
            set;
        }

        public System.String Agr1
        {
            get;
            set;
        }

        public System.String Agr2
        {
            get;
            set;
        }

        public System.String Agr3
        {
            get;
            set;
        }

        public System.String Agr4
        {
            get;
            set;
        }

        public System.String Agr5
        {
            get;
            set;
        }

        #endregion

        #region  Constructors
        public ZZ_System()
        {
            m_DataLayer = new Lib.Data.DataLayer();
        }

        #endregion

        #region Methods
        public override void ResetData()
		{
			ID = 0;
			Agr1 = string.Empty;
			Agr2 = string.Empty;
			Agr3 = string.Empty;
			Agr4 = string.Empty;
			Agr5 = string.Empty;
		}

        public void LoadData(System.Int32 v_ID)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = m_DataLayer.ExecDataTable("ZZ_SP_System", " Command,ID", "LoadData", v_ID);
                this.ResetData();
                if (dt == null || dt.Rows.Count <= 0)
                    return;
                this.FillData(dt.Rows[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override DataTable LoadData()
        {
            return null;
        }

        public override void FillData(DataRow row)
        {
            ResetData();
            if (row.Table.Columns.Contains("ID"))
                ID = Lib.Data.ValueType.GetValue(row["ID"], ID);
            if (row.Table.Columns.Contains("Agr1"))
                Agr1 = Lib.Data.ValueType.GetValue(row["Agr1"], Agr1);
            if (row.Table.Columns.Contains("Agr2"))
                Agr2 = Lib.Data.ValueType.GetValue(row["Agr2"], Agr2);
            if (row.Table.Columns.Contains("Agr3"))
                Agr3 = Lib.Data.ValueType.GetValue(row["Agr3"], Agr3);
            if (row.Table.Columns.Contains("Agr4"))
                Agr4 = Lib.Data.ValueType.GetValue(row["Agr4"], Agr4);
            if (row.Table.Columns.Contains("Agr5"))
                Agr5 = Lib.Data.ValueType.GetValue(row["Agr5"], Agr5);
        }

        public void ArgUpdate(int _ID, string ArgName, string _value)
        {
            m_DataLayer.ExecNonQuery("Update ZZ_System Set " + ArgName + "=N'" + _value + "' Where ID=" + _ID);
        }

        public override void OnUpdate()
        {
            Hashtable output = null;
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                Lib.Data.ParamHolder.ClearAll();
                Lib.Data.ParamHolder.AddParam("Command", "Update");
                Lib.Data.ParamHolder.AddParam("ID", ID);
                Lib.Data.ParamHolder.AddParam("Agr1", Agr1);
                Lib.Data.ParamHolder.AddParam("Agr2", Agr2);
                Lib.Data.ParamHolder.AddParam("Agr3", Agr3);
                Lib.Data.ParamHolder.AddParam("Agr4", Agr4);
                Lib.Data.ParamHolder.AddParam("Agr5", Agr5);
                Lib.Data.ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                m_DataLayer.ExecNonQuery("ZZ_SP_System", s_ParamName, ref output, o_ParamValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void OnDelete()
        {
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                Lib.Data.ParamHolder.ClearAll();
                Lib.Data.ParamHolder.AddParam("Command", "Delete");
                Lib.Data.ParamHolder.AddParam("ID", ID);
                Lib.Data.ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                m_DataLayer.ExecNonQuery("ZZ_SP_System", s_ParamName, o_ParamValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        #endregion
    }
}
